package com.example.canteen.service.impl;

import com.example.canteen.dao.FoodDao;
import com.example.canteen.dao.impl.FoodDaoImpl;
import com.example.canteen.domain.Food;
import com.example.canteen.service.FoodService;

import java.util.List;

public class FoodSerViceImpl implements FoodService {
    private FoodDao foodDao = new FoodDaoImpl();
    @Override
    public boolean save(Food food) {
        Food f = foodDao.findById(food.getId());
        if(f!=null) {
            return false;
        }
        foodDao.save(food);
        return true;
    }


    @Override
    public Food findOne(int id) {
        return foodDao.findById(id);
    }

    @Override
    public boolean update(Food food) {
        if(foodDao.update(food)==0) {
            return false;
        }
        return true;
    }

    @Override
    public List<Food> findAll() {
        return foodDao.findAll();
    }

    @Override
    public boolean delete(int id) {
        if (foodDao.delete(id)==0) {
            return false;
        }
        return true;
    }
}
